import requests
from bs4 import BeautifulSoup
import webbrowser
import re


class TencentParser:
    def __init__(self):
        # 解析接口地址（示例）
        self.parse_api = "https://jx.jsonplayer.com/player/?url="
        self.headers = {
            "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36"
        }

    def parse_video(self, video_url):
        # 检查URL是否为腾讯视频链接
        if not re.match(r'https?://(v.qq.com|m.v.qq.com)', video_url):
            return "请输入正确的腾讯视频链接"

        try:
            # 构造解析链接
            parse_url = self.parse_api + video_url
            # 直接打开解析后的链接
            webbrowser.open(parse_url)
            return "视频解析成功，正在打开浏览器播放"
        except Exception as e:
            return f"解析失败：{str(e)}"


def main():
    parser = TencentParser()
    while True:
        print("\n=== 腾讯视频VIP解析工具 ===")
        video_url = input("请输入腾讯视频链接（输入'q'退出）：")

        if video_url.lower() == 'q':
            break

        result = parser.parse_video(video_url)
        print(result)


if __name__ == "__main__":
    main()